const iconv = require('iconv-lite');
const { Builder, Browser, By, Key, until } = require('selenium-webdriver');

//chrome版本要和chromedriver版本一致
async function download(url) {
    let html = [];
    let driver = await new Builder()
        .forBrowser(Browser.CHROME)
        .build();

    try {
        await driver.get(url);
        const elements = await driver.findElements(By.css('.co_content8 a.ulink'))
        for (let element of elements) {
            const text = await element.getText();
            html.push(text);
        }
    } catch (err) {
        console.log(err);
    }

    // setTimeout(async () => {
    //     await driver.quit();
    // }, 50000);

    return html;
}

async function download2(url) {
    let driver = await new Builder()
        .forBrowser(Browser.CHROME)
        .build();
    await driver.get(url);
    let html = await driver.executeScript('return document.documentElement.outerHTML');
    return html;
}

async function start() {
    // let html = await download('https://www.dygod.net/html/gndy/dyzz/index.html');
    // console.log(html);

    let html = await download2('https://www.dygod.net/html/gndy/dyzz/index.html');
    console.log(html);
}

start();

